package com.onepower.admin.config;

import com.onepower.admin.authorization.TokenHelper;
import com.onepower.admin.authorization.URLInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author lixiaofeng
 * @date 2019/12/10 15:33
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {


    @Autowired
    private TokenHelper tokenHelper;

    private HandlerInterceptor getMyInterceptor(){
        return new URLInterceptor(tokenHelper);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getMyInterceptor())
                .addPathPatterns("/**")
                // 不应用拦截器的url
                .excludePathPatterns("/api/common/login");
    }
}
